package egs.clone;

//The default behaviour of clone() method inherited from the Object class is known as shallow cloning.

public class shallow implements Cloneable {
	 
    int a = 10;
    StringBuffer b = new StringBuffer("abc");
 
    public static void main(String[] args) {
    	
        shallow b1 = new shallow();
        
        try {
        	
            shallow b2 = (shallow)b1.clone();
            
            System.out.println("Before");
            
            System.out.println("b1.a=" + b1.a + " b1.b=" + b1.b);
            System.out.println("b2.a=" + b2.a + " b2.b=" + b2.b);
            
            b1.a=20;
            b1.b.append("def");
            
            System.out.println("After");
            
            System.out.println("b1.a=" + b1.a + " b1.b=" + b1.b);
            System.out.println("b2.a=" + b2.a + " b2.b=" + b2.b);
        } 
        
        catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
    }
}

